package HomeWork2;

import java.util.*;


public class d0330HomeWork {
    public static void main(String[] args) {
        int []a=new int[99];
        int []b=new int[99];
        int []c=new int[99];
        int money=0;
        for (int i = 0; i < 99; i++) {
            a[i]=(int)(Math.random()*19+1);
            b[i]=(int)(Math.random()*9999+1);
        }
        for (int i = 0; i <99; i++) {
            System.out.println("人"+String.format("%02d",a[i])+" "+b[i]+"元");
        }

        HashMap<Integer, Integer> fuck = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> shit = new HashMap<Integer, Integer>();

        for (int i = 0; i < a.length; i++) {
            if (fuck.containsKey(a[i])) {
                fuck.put(a[i], fuck.get(a[i])+ 1);
                shit.put(b[i],a[i]);
            } else {
                fuck.put(a[i], 1);
                shit.put(b[i],a[i]);
            }
        }
        /*Set<Integer> ky=fuck.keySet();
        for (Integer h:
             ky) {
            System.out.println(h+"---"+fuck.get(h));
        }*/

        // 找出map的value中最大的数字，也就是数组中数字出现最多的次数
        int maxCount = Collections.max(fuck.values());
        int maxNumber = 0;

        for (Map.Entry<Integer, Integer> entry : fuck.entrySet()) {
            // 得到value为maxCount的key，也就是数组中出现次数最多的数字
            if (maxCount == entry.getValue()) {
                maxNumber = entry.getKey();
            }
        }

       /* int maxNumber=0;
        int maxCount = Collections.max(fuck.values());
        Map.Entry<Integer,Integer> entry = (Map.Entry<Integer, Integer>) fuck.entrySet();
            for (int i = 0; i <fuck.size(); i++) {
                if (maxCount==fuck.get(i)){
                    maxNumber=entry.getKey();
                }
            }*/



        List<Map.Entry<Integer, Integer>> list = new ArrayList<Map.Entry<Integer, Integer>>(shit.entrySet());
        for (int i = 0; i <list.size(); i++) {
            if (list.get(i).getValue()==maxNumber){
                int bitch=0;
                c[i]=list.get(i).getKey();
                bitch++;
            }
        }
        for (int i = 0; i <c.length; i++) {
            if(money<c[i]){
                money=c[i];
            }
        }
        System.out.println("消费次数最多的用户：" + "人"+maxNumber+"  最高消费金额："+money+"元");

    }
}
